package com.gxan.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.gxan.common.R;

import com.gxan.pojo.RegistrationResults;
import com.gxan.service.ResumeService;
import com.gxan.service.impl.ResumeServiceImpl;
import com.gxan.utils.DateUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/resume/updateRegistrationResults")
public class EditRegistrationResultsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//获取前端传过来的参数
        String interview_result_id = request.getParameter("interview_result_id");
        String resume_id = request.getParameter("resume_id");
        String recommend_the_interview = request.getParameter("recommend_the_interview");
        String first_interviewer = request.getParameter("first_interviewer");
        String first_time = request.getParameter("first_time");
        String first_evaluation = request.getParameter("first_evaluation");
        String second_interviewer = request.getParameter("second_interviewer");
        String second_time = request.getParameter("second_time");
        String second_evaluation = request.getParameter("second_evaluation");
        String third_interviewer = request.getParameter("third_interviewer");
        String third_time = request.getParameter("third_time");
        String third_evaluation = request.getParameter("third_evaluation");
        //封装对象
        RegistrationResults registrationResults = new RegistrationResults(
                Integer.valueOf(interview_result_id),Integer.valueOf(resume_id),
                recommend_the_interview,
                first_interviewer,DateUtils.string2Date(first_time),first_evaluation,
                second_interviewer, DateUtils.string2Date(second_time), second_evaluation,
                third_interviewer,DateUtils.string2Date(third_time),third_evaluation);
        //传递service处理数据
        ResumeService resumeService =new ResumeServiceImpl();
        R r = resumeService.updateRegistrationResults(registrationResults);
        //响应到前端页面
        //返回给前端需要的R封装的数据，装换成Json方式返回
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSONObject.toJSONString(r));
        response.getWriter().flush();
        response.getWriter().close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
